package com.parking.status.sync.config;

import com.parking.status.sync.netty.client.*;
import com.parking.status.sync.netty.server.ChannelRepository;
import com.parking.status.sync.netty.server.ServerChannelInitializer;
import com.parking.status.sync.netty.server.TCPServer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by Administrator on 2015/9/17.
 */
@Configuration
public class NettyTcpConfig {

    @Value("${tcp.ip:127.0.0.1}")
    private String tcpIp;

    @Value("${tcp.port:20000}")
    private int tcpPort;

    @Bean
    public TcpClient tcpClient() {
        TcpClient tcpClient = new TcpClient(tcpIp, tcpPort);

        return tcpClient;
    }

//    @Bean
//    public RequestFinalEncoder requestFinalEncoder() {
//        return new RequestFinalEncoder();
//    }

    @Bean
    public ResponseFinalDecoder responseFinalDecoder() {
        return new ResponseFinalDecoder();
    }

    @Bean
    public ResponseBodyDecoder responseBodyDecoder() {
        return new ResponseBodyDecoder();
    }

    @Bean
    public ClientChannelInitializer clientChannelInitializer() {
        ClientChannelInitializer initializer = new ClientChannelInitializer();
        return initializer;
    }
}
